package com.tankbattle.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginWindow extends JFrame {
    private Image backgroundImage;

    public LoginWindow() {
        setTitle("坦克大战");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 加载背景图片
        backgroundImage = new ImageIcon(getClass().getResource("/resources/images/login.png")).getImage();

        // 创建自定义面板来绘制背景
        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
            }
        };
        panel.setLayout(null);

        // 创建标题标签
        JLabel titleLabel = new JLabel("坦克大战");
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 48));
        titleLabel.setForeground(Color.WHITE);
        titleLabel.setBounds(300, 100, 200, 60);
        panel.add(titleLabel);

        // 创建开始按钮
        JButton startButton = new JButton("开始游戏");
        startButton.setBounds(300, 300, 200, 40);
        startButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                SwingUtilities.invokeLater(() -> new GameWindow());
            }
        });
        panel.add(startButton);

        // 创建退出按钮
        JButton exitButton = new JButton("退出游戏");
        exitButton.setBounds(300, 360, 200, 40);
        exitButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        panel.add(exitButton);

        setContentPane(panel);
    }
}
